how to dynamically delete and add values to array